Ini_reader = {}

--读全部
function Ini_reader.load(fileName)
	assert(type(fileName) == 'string', 'Parameter "fileName" must be a string.');
	local file
	local res = pcall(function ()
		file = io.open(fileName, 'r')
	end)
	local data = {};
	if res and file then
		local section;
		for line in file:lines() do
			local tempSection = line:match('^%[([^%[%]]+)%]$');
			if(tempSection)then
				section = tonumber(tempSection) and tonumber(tempSection) or tempSection;
				data[section] = data[section] or {};
			end
			local param, value = line:match('^([%w|_]+)%s-=%s-(.+)$');
			if(param and value ~= nil)then
				if(tonumber(value))then
					value = tonumber(value);
				elseif(value == 'true')then
					value = true;
				elseif(value == 'false')then
					value = false;
				end
				if(tonumber(param))then
					param = tonumber(param);
				end
				data[section][param] = value;
			end
		end
		file:close();
	end
	return data;
end

--写全部
function Ini_reader.save(fileName, data)
	assert(type(fileName) == 'string', 'Parameter "fileName" must be a string.');
	assert(type(data) == 'table', 'Parameter "data" must be a table.');
	local file = assert(io.open(fileName, 'w+b'), 'Error loading file :' .. fileName);
	local contents = '';
	for section, param in pairs(data) do
		contents = contents .. ('[%s]\n'):format(section);
		for key, value in pairs(param) do
			contents = contents .. ('%s=%s\n'):format(key, tostring(value));
		end
		contents = contents .. '\n';
	end
	file:write(contents);
	file:close();
end